#include "MainWinPlugin.h"
#include "Common.h"
#include <QDebug>
#include <QLabel>
#include <QPushButton>
#include <QComboBox>
#include <QLineEdit>

#include <thread>
#include <chrono>



MainWinPlugin::MainWinPlugin(QObject *parent) :
    BasePlugin(MAINWIN_PLUGIN_NAME,
               MAINWIN_PLUGIN_DESCRIPTION)
{
    AddType(PluginType::User);
    AddType(PluginType::TopWidget);
}

MainWinPlugin::~MainWinPlugin()
{

}

void MainWinPlugin::OnLoad(int argc, char **argv)
{

//    std::thread t([](){
//        const QVector<int>* handle = nullptr;
//        while(1){
//            SharedInstance->GetMemReadLock("v1", (const void**)&handle);

//            for(auto& i : *handle){
//                qDebug() << i;
//            }
//            SharedInstance->UnlockMem("v1");

//            std::this_thread::sleep_for(std::chrono::microseconds(200));
//        }
//    });

//    t.detach();

}

QWidget *MainWinPlugin::GetWidget()
{
    QWidget* w = new QWidget;
    QLabel* lb = new QLabel("label");
    lb->setParent(w);
    lb->move(0,0);

    QPushButton* btn = new QPushButton("button");
    btn->setParent(w);
    btn->move(100,0);

    QComboBox* com = new QComboBox;
    com->addItem("item1");
    com->addItem("item2");
    com->addItem("item3");
    com->setParent(w);
    com->move(200,0);

    QLineEdit* le = new QLineEdit;
    le->setText("line edit");
    le->move(300,0);

    return w;
}
